home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / XFREE / xfree_compat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-24  |  7.3 KB  |  300 lines

  1. /*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  2.  *
  3.  *  Copyright (C) 1995  Koen Gadeyne
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. /***
  22.  *** xfree_compat: misc. stuff to get the XFREE code to compile. This is junk :-(
  23.  *** Written by Koen Gadeyne (kmg@barco.be)
  24.  ***
  25.  ***/
  26.  
  27.  
  28.  
  29. #include "common/compiler.h"   /* this will use the INVERTED outb() function! */
  30. #include "xfree_compat.h"
  31. #include "../misc.h"
  32.  
  33. /***************************************************************************/
  34.  
  35. /* next block is taken from xfree86/os-support/linux/lnx_video.c it was to
  36.  * idiot to include the entire os-support/linux dir here, since these
  37.  * functions were so simple...
  38.  */
  39.  
  40. Bool xf86DisableInterrupts()
  41. {
  42.         return(TRUE);
  43. }
  44.  
  45. void xf86EnableInterrupts()
  46. {
  47.         return;
  48. }
  49.  
  50.  
  51.  
  52. /***************************************************************************/
  53.  
  54.  
  55. /* next block is from xfree/accel/s3/s3TiCursor.c and Ti3026Curs.c. It was 
  56.  * cut out and placed here because it looked like a big effort to get that
  57.  * .c file to compile under SVGATextMode, and I needed only a few functions.
  58.  */
  59.  
  60. #define S3_SERVER 1
  61. #include "common_hw/Ti302X.h"
  62.  
  63. extern int vgaIOBase;
  64. extern int vgaCRIndex;
  65. extern int vgaCRReg;
  66.  
  67. /*
  68.  * s3OutTiIndReg() and s3InTiIndReg() are used to access the indirect
  69.  * 3020 registers only.
  70.  */
  71.  
  72. #ifdef __STDC__
  73. void s3OutTiIndReg(unsigned char reg, unsigned char mask, unsigned char data)
  74. #else
  75. void s3OutTiIndReg(reg, mask, data)
  76. unsigned char reg;
  77. unsigned char mask;
  78. unsigned char data;
  79. #endif
  80. {
  81.    unsigned char tmp, tmp1, tmp2 = 0x00;
  82.  
  83.    /* High 2 bits of reg in CR55 bits 0-1 (1 is cleared for the TI ramdac) */
  84.    outb(vgaCRIndex, 0x55);
  85.    tmp = inb(vgaCRReg) & 0xFC;
  86.    outb(vgaCRReg, tmp | 0x01);  /* toggle to upper 4 direct registers */
  87.    tmp1 = inb(TI_INDEX_REG);
  88.    outb(TI_INDEX_REG, reg);
  89.  
  90.    /* Have to map the low two bits to the correct DAC register */
  91.    if (mask != 0x00)
  92.       tmp2 = inb(TI_DATA_REG) & mask;
  93.    outb(TI_DATA_REG, tmp2 | data);
  94.  
  95.    /* Now clear 2 high-order bits so that other things work */
  96.    outb(TI_INDEX_REG, tmp1);  /* just in case anyone relies on this */
  97.    outb(vgaCRReg, tmp);
  98. }
  99.  
  100. #ifdef __STDC__
  101. unsigned char s3InTiIndReg(unsigned char reg)
  102. #else
  103. unsigned char s3InTiIndReg(reg)
  104. unsigned char reg;
  105. #endif
  106. {
  107.    unsigned char tmp, tmp1, ret;
  108.  
  109.    /* High 2 bits of reg in CR55 bits 0-1 (1 is cleared for the TI ramdac) */
  110.    outb(vgaCRIndex, 0x55);
  111.    tmp = inb(vgaCRReg) & 0xFC;
  112.    outb(vgaCRReg, tmp | 0x01);  /* toggle to upper 4 direct registers */
  113.    tmp1 = inb(TI_INDEX_REG);
  114.    outb(TI_INDEX_REG, reg);
  115.  
  116.    /* Have to map the low two bits to the correct DAC register */
  117.    ret = inb(TI_DATA_REG);
  118.  
  119.    /* Now clear 2 high-order bits so that other things work */
  120.    outb(TI_INDEX_REG, tmp1);  /* just in case anyone relies on this */
  121.    outb(vgaCRReg, tmp);
  122.  
  123.    return(ret);
  124. }
  125.  
  126.  
  127. /*
  128.  * s3OutTi3026IndReg() and s3InTi3026IndReg() are used to access the indirect
  129.  * 3026 registers only.
  130.  */
  131.  
  132. #ifdef __STDC__
  133. void s3OutTi3026IndReg(unsigned char reg, unsigned char mask, unsigned char data)
  134. #else
  135. void s3OutTi3026IndReg(reg, mask, data)
  136. unsigned char reg;
  137. unsigned char mask;
  138. unsigned char data;
  139. #endif
  140. {
  141.    unsigned char tmp, tmp1, tmp2 = 0x00;
  142.  
  143.    outb(vgaCRIndex, 0x55);
  144.    tmp = inb(vgaCRReg) & 0xFC;
  145.    outb(vgaCRReg, tmp | 0x00);
  146.    tmp1 = inb(0x3c8);
  147.    outb(0x3c8, reg);
  148.    outb(vgaCRReg, tmp | 0x02);
  149.  
  150.    if (mask != 0x00)
  151.       tmp2 = inb(0x3c6) & mask;
  152.    outb(0x3c6, tmp2 | data);
  153.  
  154.    outb(vgaCRReg, tmp | 0x00);
  155.    outb(0x3c8, tmp1);  /* just in case anyone relies on this */
  156.    outb(vgaCRReg, tmp);
  157. }
  158.  
  159. #ifdef __STDC__
  160. unsigned char s3InTi3026IndReg(unsigned char reg)
  161. #else
  162. unsigned char s3InTi3026IndReg(reg)
  163. unsigned char reg;
  164. #endif
  165. {
  166.    unsigned char tmp, tmp1, ret;
  167.  
  168.    outb(vgaCRIndex, 0x55);
  169.    tmp = inb(vgaCRReg) & 0xFC;
  170.    outb(vgaCRReg, tmp | 0x00);
  171.    tmp1 = inb(0x3c8);
  172.    outb(0x3c8, reg);
  173.    outb(vgaCRReg, tmp | 0x02);
  174.  
  175.    ret = inb(0x3c6);
  176.  
  177.    outb(vgaCRReg, tmp | 0x00);
  178.    outb(0x3c8, tmp1);  /* just in case anyone relies on this */
  179.    outb(vgaCRReg, tmp);
  180.  
  181.    return(ret);
  182. }
  183.  
  184.  
  185.  
  186. /*
  187.  * This piece is from s3.c from the XFree 3.1.2 code. 
  188.  */
  189.  
  190. void
  191. s3ProgramTi3025Clock(clk, n, m, p)
  192. int clk;
  193. unsigned char n;
  194. unsigned char m;
  195. unsigned char p;
  196. {
  197.    /*
  198.     * Reset the clock data index
  199.     */
  200.    s3OutTiIndReg(TI_PLL_CONTROL, 0x00, 0x00);
  201.  
  202.    if (clk != TI_MCLK_PLL_DATA) {
  203.       /*
  204.        * Now output the clock frequency
  205.        */
  206.       s3OutTiIndReg(TI_PIXEL_CLOCK_PLL_DATA, 0x00, n);
  207.       s3OutTiIndReg(TI_PIXEL_CLOCK_PLL_DATA, 0x00, m);
  208.       s3OutTiIndReg(TI_PIXEL_CLOCK_PLL_DATA, 0x00, p | TI_PLL_ENABLE);
  209.  
  210.       /*
  211.        * And now set up the loop clock for RCLK
  212.        */
  213.       s3OutTiIndReg(TI_LOOP_CLOCK_PLL_DATA, 0x00, 0x01);
  214.       s3OutTiIndReg(TI_LOOP_CLOCK_PLL_DATA, 0x00, 0x01);
  215.       s3OutTiIndReg(TI_LOOP_CLOCK_PLL_DATA, 0x00, p>0 ? p : 1);
  216.       s3OutTiIndReg(TI_MISC_CONTROL, 0x00,
  217.                     TI_MC_LOOP_PLL_RCLK | TI_MC_LCLK_LATCH | TI_MC_INT_6_8_CONTROL);
  218.  
  219.       /*
  220.        * And finally enable the clock
  221.        */
  222.       s3OutTiIndReg(TI_INPUT_CLOCK_SELECT, 0x00, TI_ICLK_PLL);
  223.    } else {
  224.       /*
  225.        * Set MCLK
  226.        */
  227.       s3OutTiIndReg(TI_MCLK_PLL_DATA, 0x00, n);
  228.       s3OutTiIndReg(TI_MCLK_PLL_DATA, 0x00, m);
  229.       s3OutTiIndReg(TI_MCLK_PLL_DATA, 0x00, p | 0x80);
  230.    }
  231. }
  232.  
  233. /* these ARK clockchip routines should be part of XFREE/common_hw/S3gendac.c */
  234.  
  235. #include "XFREE/common_hw/S3gendac.h"
  236.  
  237. static void setARKgendacpll(
  238. #if NeedFunctionPrototypes
  239. int reg, unsigned char data1, unsigned char data2
  240. #endif
  241. );
  242.  
  243. int
  244. ARKgendacSetClock(freq, clk)
  245. long freq;
  246. int clk;
  247. {
  248.    unsigned char m, n;
  249.  
  250.    commonCalcClock(freq, 1, 100000, 250000, &m, &n);
  251.  
  252.    setARKgendacpll(clk, m, n);
  253.    return 0;
  254. }
  255.  
  256. static void
  257. #if NeedFunctionPrototypes
  258. setARKgendacpll(int reg, unsigned char data1, unsigned char data2)
  259. #else
  260. setARKgendacpll(reg, data1, data2)
  261. int reg;
  262. unsigned char data1;
  263. unsigned char data2;
  264. #endif
  265. {
  266.    unsigned char tmp, tmp1;
  267.  
  268.    /* set RS2 via SEQ 0x1C */
  269.    outb(0x3C4, 0x1C);
  270.    tmp = inb(0x3C5) & 0x7F;
  271.    outb(0x3C4, tmp | 0x80);
  272.    tmp1 = inb(GENDAC_INDEX);
  273.  
  274.    outb(GENDAC_INDEX, reg);
  275.    outb(GENDAC_DATA, data1);
  276.    outb(GENDAC_DATA, data2);
  277.  
  278.    /* Now clean up our mess */
  279.    outb(GENDAC_INDEX, tmp1);
  280.    outb(0x3C5, tmp);
  281. }
  282.  
  283. /*
  284.  * set the sync_on_green on TI 302X RAMDAC's
  285.  * code borrowed from xc/programs/Xserver/hw/xfree86/accel/s3/s3init.c
  286.  */
  287. void set_ti_SOG(Bool SOG)
  288. {
  289.    unsigned char tmp, tmp1;
  290.  
  291.    /* change polarity on S3 to pass through control to the 3020 */
  292.    tmp = inb(0x3CC);
  293.    outb(0x3C2,tmp |= 0xC0);
  294.    tmp1 = 0x00;
  295.    if (!(tmp & 0x80)) tmp1 |= 0x02; /* invert bits for the 3020 */
  296.    if (!(tmp & 0x40)) tmp1 |= 0x01;
  297.    if (SOG) tmp1 |= 0x20;  /* add IOG sync */
  298.    s3OutTiIndReg(TI_GENERAL_CONTROL, 0x00, tmp1);
  299. }
  300.